import {Component} from '@angular/core';
import {NavController, NavParams} from 'ionic-angular';

import {Backend} from '../../providers/backend';
import {Forget} from './tab-my-forget';
import {TabMy} from './tab-my';
@Component({
  templateUrl: 'build/pages/tab-my/tab-my-changepaw.html'
})
export class Changepaw {

  static get parameters() {
    return [[NavController], [NavParams], [Backend]];
  }

  constructor(nav, params, backend) {
    this.nav = nav;
    this.params = params;
    this.backend = backend;
    this.menus = {};
    this.uid;
    this.password;
    this.newpassword;
    this.nerpasswordagain;
    this.wrongmessage;
    this.backend.isLogined()
      .then(result => {
        this.result = result;
        console.log(this.result);
        this.email = this.result.email;
        this.uid = this.result.uid;
      });
  }
  changepassword() {
    if (this.newpassword !== this.nerpasswordagain) {
      this.wrongmessage = '*两次输入密码不一致';
    } else {
      this.backend.changepassword(this.uid, this.password, this.newpassword)
        .then(result => {
          this.suvery = result;
          console.log(this.suvery);
          if (this.suvery.code == 3) {
            this.nav.pop();
          } else if (this.suvery.code == 0) {
            this.wrongmessage = '原密码错误';
          } else if (this.suvery.code == 1) {
            this.wrongmessage = '密码不能为空';
          } else {
            this.wrongmessage = '修改失败';
          }

        });
    }
  }
  // testpaw() {
  //   var paw = /^(?=.{6,16}$)(?![0-9]+$)(?!.*(.).*\1)[0-9a-zA-Z]+$/;
  //   if (!paw.test(this.nerpasswordagain)) {
  //     this.wrongmessage = '*请输入6-16位不完全相同的数字和字母';
  //   } else {
  //     this.wrongmessage = undefined;
  //   }
  // }
  // register() {
  //   if ((this.newpassword === this.nerpasswordagain) && typeof (this.newpassword) === 'string' && typeof (this.nerpasswordagain) === 'string' && this.wrongmessage === undefined && typeof (this.password) === 'string') {
  //     this.nav.push(TabMy, { id: 1 });
  //   } else if (this.newpassword !== this.nerpasswordagain) {
  //     this.wrongmessage = '*两次输入密码不一致';
  //   } else if (this.wrongmessage === undefined) {
  //     this.wrongmessage = '*密码不能为空';
  //   } else {
  //     this.wrongmessage = '*请输入6-16位不完全相同的数字和字母';
  //   }

  // }
}
